AUX VM Browser
A set of utilities required to run an AUX in a web browser.
Installation
- Install the NPM package
npm install @casual-simulation/aux-vm-browser
- Add the
WorkerEntry.js
file to your Webpack config:
entry: {
vm: path.resolve(
__dirname,
'node_modules',
'@casual-simulation',
'aux-vm-browser',
'html',
'WorkerEntry.js'
),
},
- Add the
iframe_host.html
file to your webpack config via the HtmlWebpackPlugin
:
new HtmlWebpackPlugin({
chunks: ['vm'],
template: path.resolve(
__dirname,
'node_modules',
'@casual-simulation',
'aux-vm-browser',
'html',
'iframe_host.html'
),
title: 'AUX VM',
filename: 'aux-vm-iframe.html',
}),
- Ensure that
aux-vm-iframe.html
is available at the root path of the site.
Usage
Connect to an AUX
import { BotManager } from '@casual-simulation/aux-vm-browser';
import { AuxUser } from '@casual-simulation/aux-vm';
start();
async function start() {
const user: AuxUser = {
id: 'myUserId',
username: 'myUsername',
name: 'myName',
token: 'mySecretToken',
isGuest: false,
};
const id = 'channelId';
const sim = new BotManager(user, id, {
isBuilder: false,
isPlayer: false,
});
await sim.init();
sim.connection.syncStateChanged.subscribe((synced) => {
if (synced) {
console.log("We're synced!");
} else {
console.log('No longer synced.');
}
});
}